from pathlib import Path

def count_words(path):
    """计算一个文件大约包含多少个单词"""
    try:
        contents = path.read_text(encoding='utf-8')
    except FileExistsError:
        print(f"Sorry,the file {path} doesn't exist.")
    else:
        words = contents.split()
        num_words = len(words)
        print(f"The file {path} has about {num_words} words.")

path = Path('day16/alice.txt')
count_words(path)